package com.ewanghuiju.app.widget.popupwindow;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.ewanghuiju.app.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import razerdp.basepopup.BasePopupWindow;

/**
 * @author sj  qq:751943509
 * @class 公共获取粘贴板的文本弹框
 * @time 2020/2/19
 */
public class CommonSearchPopup extends BasePopupWindow {

    @BindView(R.id.tv_content)
    TextView tvContent;
    private PopupItemClickCallback popupItemClickCallback;
    private String content;

    public CommonSearchPopup(Context context, PopupItemClickCallback popupItemClickCallback) {
        super(context);
        ButterKnife.bind(this, getContentView());
        this.popupItemClickCallback = popupItemClickCallback;
    }

    /**
     * 设置文本
     * @param content
     */
    public void setContent(String content) {
        this.content = content;
        if(tvContent!=null){
            tvContent.setText(content);
        }
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.popup_common_search);
    }

    @OnClick({R.id.popup_close, R.id.tv_search})
    public void doClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.popup_close:
                //关闭按钮
                dismiss();
                break;
            case R.id.tv_search:
                dismiss();
                if (popupItemClickCallback != null) {
                    popupItemClickCallback.onSureCallback(content);
                }
                break;
            default:
                break;
        }
    }
}
